package com.yfqy.app.modules.product.resource;

import com.github.pagehelper.PageInfo;
import com.yfqy.app.domain.vo.ResultVO;
import com.yfqy.app.modules.product.dto.ProductQueryDTO;
import com.yfqy.app.modules.product.service.ProductService;
import com.yfqy.app.modules.product.vo.ProductSkuVO;
import com.yfqy.app.modules.product.vo.ProductSpuVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/client/product")
public class ProductController {

    @Autowired
    public ProductService productService;

    /**
     * 详情接口
     *
     * @param productId
     * @return
     */
    @GetMapping("/detail/{productId}")
    public ResultVO<ProductSpuVO> detail(@PathVariable Long productId) {
        return ResultVO.data(productService.detail(productId));
    }


    /**
     * 详情页面中使用，推荐更多商品
     *
     * @param productId
     * @return
     */
    @PostMapping("/more/{productId}")
    public ResultVO<List<ProductSpuVO>> more(@PathVariable Long productId, @RequestBody ProductQueryDTO dto) {
        return ResultVO.data(productService.more(productId, dto));
    }

    /**
     * 分页查询
     *
     * @param productQuery
     * @return
     */
    @PostMapping("/public/products")
    public ResultVO<PageInfo<ProductSpuVO>> products(@RequestBody ProductQueryDTO productQuery) {
        return ResultVO.data(productService.products(productQuery));
    }


    @GetMapping("/skuList/{productId}")
    public ResultVO<List<ProductSkuVO>> skuList(@PathVariable Long productId) {
        return ResultVO.data(productService.skuList(productId));
    }
}
